//
//  main.c
//  求一个自然数各位数字组成的最大数
//
//  Created by apple on 2017/1/6.
//  Copyright © 2017年 apple. All rights reserved.
//

#include <stdio.h>
#include<stdio.h>
void selection(int a[],int n);

int main(){
    int N,num,i,j,y,z,h,m;
    int a[50];
    scanf("%d",&N);
    for (i=0; i<N; i++) {
        scanf("%d",&num);
        y=num;
        z=num;
        for (j=0;y>0 ; j++) {
            y =y/10;
        }
        m=j-1;
        for (; m>-1; m--) {
            a[m]=z%10;
            z=z/10;
        }
        selection(a, j);
        for (h=0; h<j; h++) {
            printf("%d",a[h]);
        }
        printf("\n");
    }
}
void selection(int a[],int n){
    int i,j,tem;
    int index;
    for (i=0; i<n-1; i++) {
        index=i;
        for (j=i+1; j<n; j++)
            if (a[j]>a[index])
                index=j;
        if (i!=index)
        {   tem=a[i];
            a[i]=a[index];
            a[index]=tem;}
        
        
    }
    
}